package com.zh.mybatis.controller;

import com.alibaba.fastjson.JSON;
import com.zh.mybatis.domain.student.entity.StudentEntity;
import com.zh.mybatis.domain.student.mapper.StudentMapper;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZH
 * @date 12:12 2021/9/1
 */
@AllArgsConstructor
@RestController
public class StudentController {
    private StudentMapper studentMapper;

    @GetMapping(value = "/one",produces = "application/json")
    @Transactional
    public  String findStudent(){
        StudentEntity student = studentMapper.findStudent(1L);
        System.out.println("student = "+ JSON.toJSONString(student));
        return JSON.toJSONString(student);
    }

    @GetMapping(value = "/one/lazy",produces = "application/json")
    @Transactional
    public  String findStudentLazy(){
        StudentEntity student = studentMapper.findStudentLazy(1L);
        System.out.println("student = "+ JSON.toJSONString(student));
        return JSON.toJSONString(student);
    }

    @GetMapping(value = "/list",produces = "application/json")
    @Transactional
    public  String findFullAll(){
        List<StudentEntity> allStudent = studentMapper.findFullAll();
        System.out.println("allStudent = "+ JSON.toJSONString(allStudent));
        return JSON.toJSONString(allStudent);
    }

    @GetMapping(value = "/list/lazy",produces = "application/json")
    @Transactional
    public  String findFullAllLazy(){
        List<StudentEntity> allStudent = studentMapper.findFullAllLazy();
        System.out.println("allStudent = "+ JSON.toJSONString(allStudent));
        return JSON.toJSONString(allStudent);
    }
}
